package com.buymobile.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.buymobile.components.page.Page;
import com.buymobile.service.GoodsService;
import com.buymobile.utils.Constant;

@Controller
public class GoodsController {

	private GoodsService goodsService;

	@RequestMapping("/admin/goods/list")
	public String searchGoods(@RequestParam(value="pageIndex",required=false) Integer pageIndex,Model model){
		if(pageIndex == null)
			pageIndex = 1;
		Map<String,Object> criteria = new HashMap<String,Object>();
		criteria.put(Constant.ORDER_BY_CLAUSE, "order by id");
		Page result = goodsService.searchGoodsByCriteria(criteria,pageIndex,2);
		model.addAttribute("result", result);
		return "/admin/goods/list";
	}
	
	@Autowired
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	
}
